//
//  FSMainTableViewController.m
//  Trade
//
//  Created by 刘沿 on 16/4/6.
//  Copyright © 2016年 刘沿. All rights reserved.
//

#import "FSMainTableViewController.h"

@interface HomeModel : FSBaseModel

@property(nonatomic,copy)NSString *  exchange;
@property(nonatomic,copy)NSString *  ksmail;
@property(nonatomic,copy)NSString *  mail;
@property(nonatomic,copy)NSString *  offiece;
@property(nonatomic,copy)NSString *  whetherExchange;
@property(nonatomic,copy)NSString *  whetherSms;
@property(nonatomic,copy)NSString * read;

@end

@implementation HomeModel

@end

@interface FSMainTableViewController ()
//登录的模型
@property (nonatomic,strong) HomeModel *homeModel;

@property (weak, nonatomic) IBOutlet UITableViewCell *firstCell;

//第三个cell待办的
@property (weak, nonatomic) IBOutlet UIImageView *daiBanImageView;

@property (weak, nonatomic) IBOutlet UIView *daiBanView;

@property (weak, nonatomic) IBOutlet UILabel *daiBanLabel;

@property (weak, nonatomic) IBOutlet UIButton *daiBanButton;

//短信view
@property (weak, nonatomic) IBOutlet UIView *duanXinView;

//代收文件左上角按钮个数
@property (weak, nonatomic) IBOutlet UIButton *waitReceiveBtn;
//待阅文件右上角

@property (weak, nonatomic) IBOutlet UIButton *waitReadBtn;


//待办文件左上角按钮个数
@property (weak, nonatomic) IBOutlet UIButton *waitWorkBtn;

//第三行cell最后一个view左上角
@property (weak, nonatomic) IBOutlet UIButton *otherWorkBtn;

//第四行cell第一个
@property (weak, nonatomic) IBOutlet UIView *alreadyView;

//跳转按钮
- (IBAction)pushVC:(id)sender;


//退出按钮
- (IBAction)logOut:(id)sender;




@end

@implementation FSMainTableViewController

//裁减图片
-(void)setupCorn:(UIButton*)btn{
    btn.layer.cornerRadius = 10;
    btn.layer.masksToBounds = YES;
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"主页";
    
    //剪裁圆形
    [self setupCorn:self.waitWorkBtn];
    [self setupCorn:self.waitReceiveBtn];
    [self setupCorn:self.otherWorkBtn];
    [self setupCorn:self.waitReadBtn];

}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    NSString *userID = [[NSUserDefaults standardUserDefaults] objectForKey:@"userID"];
    
    NSArray *array = @[@{@"userID":userID}];
    
    [HttpTools requestWithURL:@"exchmain" arrays:array method:KhomePqwoiunuMethod success:^(id JSON) {
        
        NSArray *tempArray = JSON[@"data"];
        NSDictionary *dict = [tempArray firstObject];
        //字典转模型
        self.homeModel = [[HomeModel alloc] initWitDictionary:dict];
        
        [self setupSubView];
        
    } failure:^(NSError *error) {
        
    }];

}

-(void)setupSubView{
    //是否显示代收，已收，已发
    if ([self.homeModel.whetherExchange integerValue] == 1) {
        self.firstCell.hidden = NO;
        self.alreadyView.hidden = YES;
        self.daiBanView.hidden = NO;
        self.daiBanImageView.image = [UIImage imageNamed:@"已办工作"];
        self.daiBanLabel.text = @"已办文件";
        self.otherWorkBtn.hidden = YES;
        self.daiBanButton.tag = 104;
    }else{
        self.daiBanView.hidden = NO;
        self.firstCell.hidden = YES;
        self.alreadyView.hidden = NO;
        self.otherWorkBtn.hidden = NO;
    }
// 是否显示短信平台
    if ([self.homeModel.whetherSms integerValue] == 1) {
        self.duanXinView.hidden = NO;
    }else{
        self.duanXinView.hidden = YES;
    }
    
//代收文件的右上角
    if ([self.homeModel.exchange integerValue] != 0) {
        self.waitReceiveBtn.hidden = NO;
        [self.waitReceiveBtn setTitle:self.homeModel.exchange forState:UIControlStateNormal];
    }else{
        self.waitReceiveBtn.hidden = YES;
    }
//待办文件的左上角
    if ([self.homeModel.offiece integerValue] != 0) {
        self.waitWorkBtn.hidden = NO;
        [self.waitWorkBtn  setTitle:self.homeModel.offiece forState:UIControlStateNormal];
        [self.otherWorkBtn  setTitle:self.homeModel.offiece forState:UIControlStateNormal];
    }else{
        self.waitWorkBtn.hidden = YES;
    }
    
    if ([self.homeModel.read integerValue] != 0) {
        self.waitReadBtn.hidden = NO;
        [self.waitReadBtn  setTitle:self.homeModel.read forState:UIControlStateNormal];
    }else{
        self.waitReadBtn.hidden = YES;
    }
    
    
    [self.tableView reloadData];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0 && self.firstCell.hidden) {
        return 0;
    }
    return 105;
}


//跳转的方法
- (IBAction)pushVC:(id)sender {
    
    
    
}



//退出按钮
- (IBAction)logOut:(id)sender {
    
    FSLoginViewController * loginVC =  [self.storyboard instantiateViewControllerWithIdentifier:@"LoginVC"];
    
    self.view.window.rootViewController = loginVC;
    
}
@end


















